home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 71 / MOBICLIC 71.ISO / mac / DATA / COMMUN / temp0001 / 00206_Script_GESTION_TITRAGE_BULLE < prev    next >
Text File  |  2004-12-05  |  17KB  |  443 lines

  1. -- DESCRIPTION --
  2.  
  3. on getBehaviorDescription me
  4.   return \
  5.     "Info-bulle" & RETURN & RETURN & \
  6.     "Produit une info-bulle lorsque l'utilisateur survole l'image-objet." & RETURN & RETURN & \
  7.     "Remarque : ce comportement appelle le comportement 'Affichage de texte' pour afficher le message. " & \
  8.     "Le comportement 'Affichage de texte' doit Ωtre liΘ α une image-objet distincte contenant un acteur champ ou un acteur texte." & RETURN & RETURN & \
  9.     "Si une telle image-objet existe, elle sera automatiquement sΘlectionnΘe dans la boεte de dialogue ParamΦtres des comportements." & RETURN & RETURN & \
  10.     "Pour que l'info-bulle apparaisse dans une position donnΘe par rapport α l'image-objet actuelle, sΘlectionnez la position adΘquate dans la boεte de dialogue ParamΦtres des comportements et vΘrifiez que le comportement 'Affichage de texte' associΘ est dΘfini pour rΘagir en tant qu'info-bulle. " & \
  11.     "Si le comportement 'Affichage de texte' est dΘfini pour agir en tant que barre d'Θtat, il ignore toutes les donnΘes de positionnement et apparaεt dans une position fixe." & RETURN & RETURN & \
  12.     "Vous pouvez choisir de faire apparaεtre l'info-bulle au survol ou uniquement si la souris s'attarde sur l'image-objet pendant une pΘriode donnΘe. " & \
  13.     "Vous pouvez Θgalement choisir de faire disparaεtre l'info-bulle lorsque l'utilisateur clique sur l'image-objet." & RETURN & RETURN & \
  14.     "La boεte de dialogue ParamΦtres du comportement dispose d'un espace limitΘ pour la saisie du contenu de l'info-bulle. " & \
  15.     "Elle n'accepte pas les chaεnes contenant un caractΦre de retour α la ligne. " & \
  16.     "Pour afficher une longue info-bulle consistant de plusieurs lignes de texte devant apparaεtre α la position de cette image-objet, vous devrez envoyer un message contenant la chaεne requise α ce comportement. " & \
  17.     "Par exemple :" & RETURN & RETURN & \
  18.     "SendSprite (1, #Tooltip_SetMessage, \" & QUOTE & "Ce message consiste en\" & QUOTE & "RETURN\" & QUOTE & "deux lignes de texte\" & QUOTE & ")" & RETURN & RETURN & \
  19.     "Cela produit le message suivant lorsque la souris survole l'image-objet 1 :" & RETURN & RETURN & \
  20.     "Ce message consiste en" & RETURN & \
  21.     "deux lignes de texte" & RETURN & RETURN & \
  22.     "Si l'info-bulle produite par ce comportement doit Ωtre affichΘe dans une barre d'Θtat, cette Θtape n'est pas nΘcessaire. " & \
  23.     "Le comportement 'Affichage de texte' assure qu'une longue ligne de texte est mise α la ligne dans la barre d'Θtat et qu'une barre de dΘfilement apparaεt si nΘcessaire." & RETURN & RETURN & \
  24.     "Types d'acteurs autorisΘs :" & RETURN & \
  25.     "tous" & RETURN & RETURN & \
  26.     "ParamΦtres :" & RETURN & \
  27.     "* Texte de l'info-bulle (chaεne d'une ligne)" & RETURN & \
  28.     "* DΘlai avant l'affichage de l'info-bulle (en battements)" & RETURN & \
  29.     "* Masquer l'info-bulle lors d'un clic sur l'image-objet ? (TRUE | FALSE)" & RETURN & \
  30.     "* Position de l'info-bulle par rapport α l'image-objet (non prise en compte si le comportement 'Affichage de texte' est dΘfini pour rΘagir en tant que barre d'Θtat)." & RETURN & \
  31.     "* NumΘro de l'image-objet dans laquelle l'info-bulle doit Ωtre affichΘe. " & \
  32.     "(Le comportement 'Affichage de texte' doit Ωtre liΘ α cette image-objet. " & \
  33.     "Si l'image-objet est dΘplacΘe, une alerte vous invitera α mettre les paramΦtres de comportement α jour)." & RETURN & RETURN & \
  34.     "MΘthodes publiques :" & RETURN & \
  35.     "* DΘfinir le message de l'info-bulle (permet l'utilisation du caractΦre de retour α la ligne)" & RETURN & \
  36.     "* Obtenir la rΘfΘrence du comportement" & RETURN & RETURN & \
  37.     "Comportements associΘs :" & RETURN & \
  38.     "* Affichage de texte - Essentiel : doit Ωtre liΘ α une image-objet champ ou texte couvrant le mΩme nombre d'images." & RETURN & RETURN & \
  39.     "Vous pouvez trouver le comportement 'Affichage de texte' dans Palette des bibliothΦques, sous Contr⌠les > Affichage de texte."
  40. end getBehaviorDescription
  41.  
  42.  
  43. on getBehaviorTooltip me
  44.   return \
  45.     "Utilisable avec n'importe quel type d'acteur." & RETURN & RETURN & \
  46.     "Produit une info-bulle lorsque la souris survole l'image-objet." & RETURN & RETURN & \
  47.     "Ce comportement exige la disponibilitΘ du comportement 'Affichage de texte' dans une image-objet champ ou texte pour afficher les messages qu'il produit. " & \
  48.     "Si aucune telle image-objet n'est disponible, une alerte apparaεt (α la programmation uniquement)." & RETURN & RETURN & \
  49.     "Le paramΦtre dΘfini pour le comportement 'Affichage de texte' associΘ dΘtermine si le message de l'info-bulle apparaεt dans une barre d'Θtat ou en tant qu'affichage temporaire de l'info-bulle sur l'image-objet ou α proximitΘ de cette image-objet."
  50. end getBehaviorTooltip
  51.  
  52.  
  53.  
  54. -- NOTES FOR DEVELOPERS --
  55.  
  56. -- The tool tip member appears in a separate sprite: myDisplaySprite.  This
  57. -- behavior merely tells the 'Display Text' behavior on myDisplaySprite what
  58. -- text to display.  Before it can do this, it must first discover the memory
  59. -- address where the 'Display Text' behavior is stored.  It does this through
  60. -- the  EnrollDisplaySprite handler.  This is not called on beginSprite
  61. -- since, logically, myDisplaySprite will be in a higher channel.  If both
  62. -- sprites begin in the same frame, myDisplaySprite may not have been
  63. -- initialised yet.
  64.  
  65. -- You may have more than one sprite with the 'Display Text' behavior.  It may
  66. -- therefore be important to ensure that the Tooltip is sent to the right
  67. -- sprite.  However, while authoring, sprites tend to get moved around.  The
  68. -- EnrollDisplaySprite does its best to find a new instance of the
  69. -- 'Display Text' behavior, but it warns the author that a conflict may be
  70. -- occurring.
  71. -- 
  72. -- DECIDING WHEN TO DISPLAY THE TOOL TIP
  73. -- The tooltip should only appear when the mouse is over the current sprite.
  74. -- You may want the it only to be visible when the mouse is up.  The
  75. -- CheckStatus handler, called on each prepareFrame analyses the position and
  76. -- state of the mouse, and either calls ShowTip, HideTip, or leaves things as
  77. -- they are.
  78. --
  79. -- HideTip doesn't in fact hide anything.  It merely displays an empty string.
  80. -- If the 'Display Text' behavior is set to act as a Tooltip, it will move its
  81. -- sprite off-stage.  If it is set to act as a Status Bar, it will simply empty.
  82. --
  83. -- Since many behaviors may be sending messages to myDisplaySprite, I make sure
  84. -- that these messages don't conflict.  To do this, I use a boolean property:
  85. -- myDisplayFlag.  This toggles between TRUE and FALSE.  While it is TRUE, no
  86. -- further ShowTip messages are generated.  It is set to FALSE when the tool
  87. -- tip is hidden: HideTip is thus also only called once.
  88. --
  89. -- I could have chosen to use mouseEnter and mouseLeave to show and hide the
  90. -- tip.  This technique would make the tool tip appear immediately.  I chose to
  91. -- allow up to 2 seconds delay (120 ticks) before showing the tip.  Instead of
  92. -- using mouseEnter to trigger the ShowTip call directly, I use it to 
  93. -- calculate the value of the ticks when the call should be make.  I store the
  94. -- result in a property: myStartTicks.  By setting myStartTicks to
  95. -- the maxInteger on mouseLeave, I can be sure that ShowTip will not be
  96. -- triggered.
  97. --
  98. -- POSITION OF TOOL TIP
  99. -- ShowTip calculates where the tool tip should (ideally) be shown.  The
  100. -- 'Display Text' behavior on myDisplaySprite may overrule this for one of two
  101. -- reasons:
  102. --  * You have set the 'Display Text' behavior to act as a Status bar
  103. --  * The ideal position of the tool tip would place it (partially) off-stage.
  104. --
  105. -- See the 'Notes for Developers' in the 'Display Text' behavior for more
  106. -- details.
  107.  
  108.  
  109.  
  110. -- HISTORY --
  111.  
  112. --  1 October 1998: Written for the D7 Behaviors Palette by James Newton
  113. -- 29 October 1998: Descriptions improved, myPosition property extended.
  114. --  7 January 2000: Added isOKToAttach and substituteStrings event handlers.
  115. --                  Removed redundant error checking. - Karl Miller
  116.  
  117.  
  118.  
  119. -- PROPERTIES --
  120.  
  121. property mySprite
  122. -- error checking
  123. property getPDLError
  124. -- author-defined parameters
  125. property myString
  126. property myDelay
  127. property myPosition
  128. property myDisplaySprite
  129. property myHideFlag
  130. -- internal properties
  131. property myDisplayList
  132. property myStartTicks
  133. property myDisplayFlag
  134.  
  135.  
  136. -- EVENT HANDLERS --
  137.  
  138. on beginSprite me
  139.   Initialize me
  140. end beginSprite
  141.  
  142.  
  143. on prepareFrame me
  144.   CheckStatus me
  145. end prepareFrame
  146.  
  147.  
  148. on mouseEnter me
  149.   myStartTicks = the ticks + myDelay
  150. end mouseEnter
  151.  
  152.  
  153. on mouseLeave me
  154.   myStartTicks = the maxinteger
  155. end mouseLeave
  156.  
  157.  
  158.  
  159. -- CUSTOM HANDLERS --
  160.  
  161. on Initialize me -- sent by beginSprite
  162.   mySprite = sprite(me.spriteNum)
  163.   myMember = mySprite.member
  164.   myDisplayList = []
  165.   myStartTicks = the maxinteger
  166. end Initialize
  167.  
  168.  
  169. on CheckStatus me
  170.   if myStartTicks < the ticks  then
  171.     if myHideFlag then
  172.       if the mouseDown then
  173.         if myDisplayFlag then
  174.           HideTip me
  175.         end if
  176.         exit
  177.       end if
  178.     end if
  179.     
  180.     if myDisplayFlag then exit
  181.     
  182.     ShowTip me
  183.   else if myDisplayFlag then
  184.     HideTip me
  185.   end if
  186. end CheckStatus
  187.  
  188.  
  189. on ShowTip me -- sent by prepareFrame
  190.   myDisplayFlag = TRUE
  191.   case myPosition of
  192.     "au centre au-dessus":
  193.       theAlignment = #bottomCenter
  194.       displayLoc = point ((mySprite.left + mySprite.right) / 2, mySprite.top)
  195.     "au centre en dessous":
  196.       displayLoc = point ((mySprite.left + mySprite.right) / 2, mySprite.bottom)
  197.       theAlignment = #topCenter
  198.     "en haut α gauche":
  199.       displayLoc = point (mySprite.left, mySprite.top)
  200.       theAlignment = #topLeft
  201.     "en haut α droite":
  202.       displayLoc = point (mySprite.right, mySprite.top)
  203.       theAlignment = #topRight
  204.     "au centre":
  205.       centerH = (mySprite.left + mySprite.right) / 2
  206.       centerV = (mySprite.top + mySprite.bottom) / 2
  207.       displayLoc = point (centerH, centerV)
  208.       theAlignment = #center
  209.     "en bas α gauche":
  210.       displayLoc = point (mySprite.left, mySprite.bottom)
  211.       theAlignment = #bottomLeft
  212.     "en bas α droite":
  213.       displayLoc = point (mySprite.right, mySprite.bottom)
  214.       theAlignment = #bottomRight
  215.     "au point d'alignement":
  216.       displayLoc = mySprite.loc
  217.       theAlignment = #center
  218.     "sous la souris":
  219.       displayLoc = the mouseLoc
  220.       theAlignment = #center
  221.   end case
  222.   
  223.   if not myDisplayList.count() then
  224.     EnrollDisplaySprite me
  225.   end if
  226.   
  227.   call #DisplayText_SetText, myDisplayList, myString, displayLoc, theAlignment  
  228.   
  229. end ShowTip
  230.  
  231.  
  232. on HideTip me -- sent by prepareFrame
  233.   
  234.   myDisplayFlag = FALSE
  235.   if not myDisplayList.count() then
  236.     EnrollDisplaySprite me
  237.   end if
  238.   
  239.   call #DisplayText_SetText, myDisplayList, EMPTY
  240.   
  241. end HideTip
  242.  
  243.  
  244. on EnrollDisplaySprite me
  245.   -- Enroll the 'Display Text' behavior
  246.   sendSprite (myDisplaySprite, #DisplayText_Enroll, myDisplayList)
  247.   if not myDisplayList.count() then
  248.     -- Try to find a sprite with the 'Display Text' behavior anyway
  249.     sendAllSprites (#DisplayText_Enroll, myDisplayList)
  250.     if not myDisplayList.count() then
  251.       ErrorAlert (me, #noValidSprites, myDisplaySprite)
  252.     else
  253.       -- Notify author of change
  254.       ErrorAlert (me, #invalidSpriteNumber, myDisplaySprite)
  255.     end if
  256.   end if
  257. end EnrollDisplaySprite
  258.  
  259.  
  260. on GetDisplaySprite me
  261.   -- Checks the scriptList of each sprite in this frame for 'Display Text'
  262.   displayScriptMember = the number of member ("Affichage de texte")
  263.   if displayScriptMember > 0 then
  264.     displayScriptMember = member (displayScriptMember)
  265.     repeat with theSprite = 1 to the lastChannel
  266.       theScripts = sprite (theSprite).scriptList
  267.       scriptCount = theScripts.count()
  268.       repeat while scriptCount
  269.         if theScripts[scriptCount][1] = displayScriptMember then
  270.           return theSprite
  271.         end if
  272.         scriptCount = scriptCount - 1
  273.       end repeat
  274.     end repeat
  275.   end if
  276.   return the currentSpriteNum + 1
  277. end GetDisplaySprite
  278.  
  279.  
  280.  
  281. -- PUBLIC METHODS (responses to #sendSprite, #sendAllSprites, #call) --
  282.  
  283. on Tooltip_SetMessage me, theString
  284.   -- Allows you to set a more complex message that can be done through the
  285.   -- Behavior Parameters Dialog, or to change it at runtime
  286.   
  287.   -- Error check
  288.   case ilk (theString) of
  289.     #string: -- nothing
  290.     otherwise
  291.       return #invalidTypeError
  292.   end case
  293.   -- End of error check
  294.   
  295.   myString = theString
  296. end Tooltip_SetMessage
  297.  
  298.  
  299. on Tooltip_GetReference me
  300.   -- Returns a reference to the behavior for Lingo calls
  301.   return me
  302. end Tooltip_GetReference
  303.  
  304.  
  305.  
  306. -- ERROR CHECKING --
  307.  
  308. on ErrorAlert me, theError, data
  309.   -- sent by Initialize
  310.   -- Determine the behavior's name
  311.   behaviorName = string (me)
  312.   delete word 1 of behaviorName
  313.   delete the last word of behaviorName
  314.   delete the last word of behaviorName
  315.   -- Convert #data to useful value
  316.   case data.ilk of
  317.     #void: data = "<void>"
  318.     #symbol: data = "#"&data
  319.   end case
  320.   
  321.   case theError of
  322.     #invalidSpriteNumber:
  323.       if the runMode = "Author" then
  324.         message = substituteStrings(me, \
  325. "L'image-objet ^3 n'a pas rΘpondu α un appel #DisplayText. " & \
  326.     "Une autre image-objet va Ωtre utilisΘe. " & \
  327.     "Veuillez ouvrir la boεte de dialogue ParamΦtres du comportement et choisir l'image-objet devant servir α afficher le message d'info-bulle.", \
  328. ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": data])
  329.       end if
  330.       
  331.       alert(message)
  332.       
  333.     #noValidSprites:
  334.       if the runMode = "Author" then
  335.         message = substituteStrings(me, \
  336. "Erreur de comportement : Image ^0, Image-objet ^1" & RETURN & \
  337.     "Comportement ^2" & RETURN & \
  338.     "Aucune image-objet n'a rΘpondu α un appel #DisplayText." & RETURN & \
  339.     "VΘrifiez que le comportement '^3' est liΘ α un champ ou texte situΘ dans les mΩmes images que l'image-objet ^1.", \
  340. ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": "Affichage de texte"])
  341.       end if
  342.       
  343.       alert(message)
  344.       
  345.   end case
  346.   
  347.   
  348. end ErrorAlert
  349.  
  350. on substituteStrings(me, parentString, childStringList) --------------
  351.   -- 
  352.   -- * Modifies parentString so that the strings which appear as
  353.   --   properties in childStringList are replaced by the values
  354.   --   associated with those properties.
  355.   --
  356.   -- <childStringList> has the format ["^1": "replacement string"]
  357.   --------------------------------------------------------------------
  358.   
  359.   i = childStringList.count()
  360.   repeat while i
  361.     tempString = ""
  362.     dummyString  = childStringList.getPropAt(i)
  363.     replacement  = childStringList[i]
  364.     lengthAdjust = dummyString.char.count - 1
  365.     repeat while TRUE
  366.       position = offset(dummyString, parentString)
  367.       if not position then
  368.         parentString = tempString&parentString
  369.         exit repeat
  370.       else
  371.         if position <> 1 then
  372.           tempString = tempString&parentString.char[1..position - 1]
  373.         end if
  374.         tempString = tempString&replacement
  375.         delete parentString.char[1..position + lengthAdjust]
  376.       end if
  377.     end repeat
  378.     i = i - 1
  379.   end repeat
  380.   
  381.   return parentString
  382. end substituteStrings 
  383.  
  384. -- AUTHOR-DEFINED PARAMETERS --
  385.  
  386. on isOKToAttach (me, aSpriteType)
  387.   return aSpriteType = #graphic
  388. end isOKToAttach
  389.  
  390. on getPropertyDescriptionList me
  391.   
  392.   -- try to find a sprite which has the 'Display Text' behavior attached
  393.   displaySprite = GetDisplaySprite (me)
  394.   
  395.   return \
  396. [ \
  397.  #myString: \
  398.  [ \
  399.   #comment:  "Texte de l'info-bulle", \
  400.   #format:   #string, \
  401.    #default: "InsΘrez une ligne d'info-bulle dans cet espace" \
  402.  ], \
  403.  #myDelay: \
  404.  [ \
  405.   #comment: "DΘlai avant l'affichage de l'info-bulle (battements) :", \
  406.   #format:  #integer, \
  407.   #range:  [#min: 0, #max: 120], \
  408.   #default:  30 \
  409.  ], \
  410.  #myHideFlag: \
  411.  [ \
  412.   #comment: "Masquer l'info-bulle lors d'un clic sur l'image-objet ?", \
  413.   #format:  #boolean, \
  414.   #default:  TRUE \
  415.  ], \
  416.  #myPosition: \
  417.  [ \
  418.   #comment: "Position de l'info-bulle p/r α l'image-objet (voir notes) :", \
  419.   #format:  #string, \
  420.   #range:  \
  421.   [ \
  422.    "au centre au-dessus", \
  423.    "en haut α gauche", \
  424.    "en haut α droite", \
  425.    "au centre", \
  426.    "en bas α gauche", \
  427.    "en bas α droite", \
  428.    "au centre en dessous", \
  429.    "au point d'alignement", \
  430.    "sous la souris" \
  431.   ], \
  432.   #default: "au centre" \
  433.  ], \
  434.  #myDisplaySprite: \
  435.  [ \
  436.   #comment: "Image-objet dans laquelle l'info-bulle doit Ωtre affichΘe :", \
  437.   #format:  #integer, \
  438.   #range:   [#min: 1, #max: the lastChannel], \
  439.   #default:  displaySprite \
  440.  ] \
  441. ]
  442. end getPropertyDescriptionList
  443.